<template>
  <div>
    <el-dialog
      :title="modalData['type']==='update'?'更新商品分类':'新建商品分类'"
      center
      destroy-on-close
      :visible.sync="modalVisible"
      :append-to-body="true"
      :before-close="closeModal"
    >
      <el-form :model="form" ref="form">
        <el-form-item
          prop="name"
          label="分类名称："
          label-width="100px"
          :rules="[{required:true,message:'名称不能为空',trigger:'blur'}]"
        >
          <el-input v-model="form.name" autocomplete="off" placeholder="请填写分类名称"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button type="primary" @click="saveData()">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  props: {
    modalVisible: {
      type: Boolean,
      default: false
    },
    modalData: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      form:modalData
    };
  },
  methods: {
    async saveData() {
      if (!this.modalData.name) return;
      await this.$emit("saveCate", this.modalData);
    },
    closeModal(e) {
      this.moadlData = {};
      this.$emit("close", "");
    }
  }
};
</script>
<style lang='scss' scoped>
</style>